package org.zk.dubbo_consumer.controller;


import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.zk.entity.Course;
import org.zk.entity.Like;
import org.zk.entity.User;
import org.zk.service.LikeService;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Alicelonely
 * @since 2019-12-11
 */
@Controller
@RequestMapping("/like")
public class LikeController {

    @Resource
    LikeService likeService;

    @RequestMapping("/toCollect")
    public ModelAndView getLikeId(int userId){
        List<Like> list=likeService.getLikeId(userId);
        ModelAndView mv=new ModelAndView("person/collection");
        mv.addObject("list",list);
        return mv;
//        return new ModelAndView("person/collection");
    }

    //添加收藏
    @ResponseBody
    @RequestMapping("addLike")
    public String addLike(Integer likeId, int userId, Integer courseId, HttpSession session){
        Like like=new Like();
        like.setLikeId(likeId);
        User user=new User();
        user.setUserId(userId);
        Course course=new Course();
        course.setCourseId(courseId);
//        session.getAttribute("like");
//        session.getAttribute("user");
//        session.getAttribute("course");
        likeService.addLike(like);
        return "course/toCourseMsg";
    }

    //删除收藏
    @ResponseBody
    @RequestMapping("del")
    public String delLike(int likeId){
         likeService.delLike(likeId);
         return "course/toCourseMsg";
    }

}

